package fregat.microchip.usb;

import fregat.microchip.usb.device.timer0;
import fregat.microchip.usb.device.timer1;

public class configCommand {
		
//	T0CON_T			t0con;
//	T1CON_T			t1con;
//	TMR0L_T			tmr0l;
//	TMR0H_T			tmr0h;
//	TMR1L_T			tmr1l;
//	TMR1H_T			tmr1h;
//	ADCON0_T		adcon0;
//	ADCON1_T		adcon1;
//	ADCON2_T		adcon2;
	
	private static final byte CONFIG_CNTRL = 3;
	private byte command[];
	private timer0 t0;
	private timer1 t1;
	private byte mode;
	
	public static final byte SINGLE_MODE 	= (byte)0x40;
	public static final byte PACKET_MODE	= (byte)0x80;
	public configCommand (timer0 t0_, timer1 t1_)
	{
		t0 = t0_;
		t1 = t1_;
		mode = configCommand.SINGLE_MODE;
		command = new byte[10];
		command[0] = configCommand.CONFIG_CNTRL;
		for (int i = 1; i < command.length; ++i)
			command[i] = 0;
		command[7] = configCommand.SINGLE_MODE;
	}
	public configCommand (byte[] b)
	{
		command = new byte[10];
		for (int i = 0; i < b.length; ++i)
			command[i] = b[i];
	}
	
	public void setSingleMode ()
	{
		command[7] |= command[7] & (byte)0xc0 | configCommand.SINGLE_MODE;
	}
	
	public void setPacketMode ()
	{
		command[7] |= command[7] & (byte)0xc0 | configCommand.PACKET_MODE;
	}
	
	public void enableADC ()
	{
		command[7] |= (byte)0x1; 
	}
	
	public void setField (byte b, int offset)
	{
		command[offset] = b;
	}
	
	public void setBufferTimer0 (int v)
	{
		t0.setBuffer(v);
//		command[3] = (byte)(v & 0xff);
//		command[4] = (byte)((v >> 8) & 0xff);
	}
	public void setBufferTimer1 (int v)
	{
		t1.setBuffer(v);
//		command[5] = (byte)(v & 0xff);
//		command[6] = (byte)((v >> 8) & 0xff);
	}
	public void setADCON0 (byte b)
	{
		command[7] = b;
	}
	public void setADCON1 (byte b)
	{
		command[8] = b;
	}
	public void setADCON2 (byte b)
	{
		command[9] = b;
	}
	
	public byte[] toByteArray ()
	{
		return command;
	}

}
